
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Noifelse · My Study Note</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="yanglonglong">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-toggle-chapters/toggle.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-flexible-alerts/style.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-theme-comscore/test.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="socket.html" />
    
    
    <link rel="prev" href="jvm.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
        
        <li>
            <a href="https://www.yangllong.top/" target="_blank" class="custom-link">My Blog</a>
        </li>
    
    

    
    <li class="divider"></li>
    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../Linux相关/">
            
                <a href="../Linux相关/">
            
                    
                    Linux相关
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../Linux相关/make工具的使用.html">
            
                <a href="../Linux相关/make工具的使用.html">
            
                    
                    Make工具的使用
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../springboot/">
            
                <a href="../springboot/">
            
                    
                    Springboot
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../springboot/springboot一些遇到的问题.html">
            
                <a href="../springboot/springboot一些遇到的问题.html">
            
                    
                    Springboot一些遇到的问题
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../vue/">
            
                <a href="../vue/">
            
                    
                    Vue
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../vue/vue+ssm跨域问题.html">
            
                <a href="../vue/vue+ssm跨域问题.html">
            
                    
                    Vue+Ssm跨域问题
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../vue/vue-cli3.html">
            
                <a href="../vue/vue-cli3.html">
            
                    
                    Vue Cli3
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../vue/安装vue.html">
            
                <a href="../vue/安装vue.html">
            
                    
                    安装Vue
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../其他/">
            
                <a href="../其他/">
            
                    
                    其他
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../其他/分布式系统.html">
            
                <a href="../其他/分布式系统.html">
            
                    
                    分布式系统
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../其他/图解http.html">
            
                <a href="../其他/图解http.html">
            
                    
                    图解Http
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../其他/消息队列.html">
            
                <a href="../其他/消息队列.html">
            
                    
                    消息队列
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../其他/爬虫.html">
            
                <a href="../其他/爬虫.html">
            
                    
                    爬虫
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../刷题/">
            
                <a href="../刷题/">
            
                    
                    刷题
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../刷题/NOJ.html">
            
                <a href="../刷题/NOJ.html">
            
                    
                    NOJ
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../刷题/leetcode/">
            
                <a href="../刷题/leetcode/">
            
                    
                    Leetcode
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../刷题/leetcode/107简单题.html">
            
                <a href="../刷题/leetcode/107简单题.html">
            
                    
                    107简单题
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.3.1" data-path="../刷题/leetcode/2两数相加.html">
            
                <a href="../刷题/leetcode/2两数相加.html">
            
                    
                    2两数相加
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3.2" data-path="../刷题/leetcode/3无重复子串的最大长度.html">
            
                <a href="../刷题/leetcode/3无重复子串的最大长度.html">
            
                    
                    3无重复子串的最大长度
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="../刷题/扇贝杯csdn.html">
            
                <a href="../刷题/扇贝杯csdn.html">
            
                    
                    扇贝杯Csdn
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="../刷题/排序算法.html">
            
                <a href="../刷题/排序算法.html">
            
                    
                    排序算法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.6" data-path="../刷题/蓝桥杯.html">
            
                <a href="../刷题/蓝桥杯.html">
            
                    
                    蓝桥杯
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.7" data-path="../刷题/蓝桥杯热身赛.html">
            
                <a href="../刷题/蓝桥杯热身赛.html">
            
                    
                    蓝桥杯热身赛
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.8" data-path="../刷题/计算机等级考试(C语言">
            
                <span>
            
                    
                    计算机等级考试(C语言)
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../博客/">
            
                <a href="../博客/">
            
                    
                    博客
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../博客/next主题配置.html">
            
                <a href="../博客/next主题配置.html">
            
                    
                    Next主题配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../博客/一些问题的记录.html">
            
                <a href="../博客/一些问题的记录.html">
            
                    
                    一些问题的记录
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="./">
            
                <a href="./">
            
                    
                    学习Java
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="AQS.html">
            
                <a href="AQS.html">
            
                    
                    AQS
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="HashMap的简单实现.html">
            
                <a href="HashMap的简单实现.html">
            
                    
                    HashMap的简单实现
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="JavaByteCode.html">
            
                <a href="JavaByteCode.html">
            
                    
                    JavaByteCode
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.4" data-path="Java基础.html">
            
                <a href="Java基础.html">
            
                    
                    Java基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.5" data-path="Java多线程.html">
            
                <a href="Java多线程.html">
            
                    
                    Java多线程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.6" data-path="Java多线程并发.html">
            
                <a href="Java多线程并发.html">
            
                    
                    Java多线程并发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.7" data-path="Java爬虫.html">
            
                <a href="Java爬虫.html">
            
                    
                    Java爬虫
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.8" data-path="Java集合.html">
            
                <a href="Java集合.html">
            
                    
                    Java集合
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.9" data-path="java常用类.html">
            
                <a href="java常用类.html">
            
                    
                    Java常用类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.10" data-path="jvm.html">
            
                <a href="jvm.html">
            
                    
                    Jvm
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.8.11" data-path="noifelse.html">
            
                <a href="noifelse.html">
            
                    
                    Noifelse
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.12" data-path="socket.html">
            
                <a href="socket.html">
            
                    
                    Socket
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.13" data-path="一些Java方法.html">
            
                <a href="一些Java方法.html">
            
                    
                    一些Java方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.14" data-path="一些其他人写的博客.html">
            
                <a href="一些其他人写的博客.html">
            
                    
                    一些其他人写的博客
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.15" data-path="硬核空间.html">
            
                <a href="硬核空间.html">
            
                    
                    硬核空间
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.16" data-path="遇到的问题.html">
            
                <a href="遇到的问题.html">
            
                    
                    遇到的问题
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.17" data-path="阻塞队列.html">
            
                <a href="阻塞队列.html">
            
                    
                    阻塞队列
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../安卓开发/">
            
                <a href="../安卓开发/">
            
                    
                    安卓开发
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="../安卓开发/First App.html">
            
                <a href="../安卓开发/First App.html">
            
                    
                    First App
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.2" data-path="../安卓开发/problems.html">
            
                <a href="../安卓开发/problems.html">
            
                    
                    Problems
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../工具/">
            
                <a href="../工具/">
            
                    
                    工具
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.10.1" data-path="../工具/IDEA.html">
            
                <a href="../工具/IDEA.html">
            
                    
                    IDEA
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.2" data-path="../工具/docker.html">
            
                <a href="../工具/docker.html">
            
                    
                    Docker
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.3" data-path="../工具/github.html">
            
                <a href="../工具/github.html">
            
                    
                    Github
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../数据库/">
            
                <a href="../数据库/">
            
                    
                    数据库
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.11.1" data-path="../数据库/MVCC.html">
            
                <a href="../数据库/MVCC.html">
            
                    
                    MVCC
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.2" data-path="../数据库/MySQL.html">
            
                <a href="../数据库/MySQL.html">
            
                    
                    MySQL
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.3" data-path="../数据库/Redis.html">
            
                <a href="../数据库/Redis.html">
            
                    
                    Redis
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="../数据结构知识/">
            
                <a href="../数据结构知识/">
            
                    
                    数据结构知识
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.12.1" data-path="../数据结构知识/大话数据结构笔记1.html">
            
                <a href="../数据结构知识/大话数据结构笔记1.html">
            
                    
                    大话数据结构笔记1
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.2" data-path="../数据结构知识/大话数据结构笔记2.html">
            
                <a href="../数据结构知识/大话数据结构笔记2.html">
            
                    
                    大话数据结构笔记2
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="../面试笔试/">
            
                <a href="../面试笔试/">
            
                    
                    面试笔试
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.13.1" data-path="../面试笔试/字节跳动5月11日笔试.html">
            
                <a href="../面试笔试/字节跳动5月11日笔试.html">
            
                    
                    字节跳动5月11日笔试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.2" data-path="../面试笔试/阿里3月23日笔试.html">
            
                <a href="../面试笔试/阿里3月23日笔试.html">
            
                    
                    阿里3月23日笔试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.3" data-path="../面试笔试/面试突击.html">
            
                <a href="../面试笔试/面试突击.html">
            
                    
                    面试突击
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >Noifelse</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <p>&#x4E00;&#x822C;&#x6765;&#x8BF4;&#x6211;&#x4EEC;&#x6B63;&#x5E38;&#x7684;&#x540E;&#x53F0;&#x7BA1;&#x7406;&#x7CFB;&#x7EDF;&#x90FD;&#x6709;&#x6240;&#x8C13;&#x7684;&#x89D2;&#x8272;&#x7684;&#x6982;&#x5FF5;</p>
<p>&#x4E0D;&#x540C;&#x7BA1;&#x7406;&#x5458;&#x6743;&#x9650;&#x4E0D;&#x4E00;&#x6837;&#xFF0C;&#x80FD;&#x591F;&#x884C;&#x4F7F;&#x7684;&#x64CD;&#x4F5C;&#x4E5F;&#x4E0D;&#x4E00;&#x6837;</p>
<p>&#x6BD4;&#x5982;&#xFF1A;</p>
<ul>
<li>&#x7CFB;&#x7EDF;&#x7BA1;&#x7406;&#x5458;&#xFF08;ROLE_ROOT_ADMIN&#xFF09;&#xFF1A;&#x6709;A&#x64CD;&#x4F5C;&#x6743;&#x9650;</li>
<li>&#x8BA2;&#x5355;&#x7BA1;&#x7406;&#x5458;&#xFF08;ROLE_ORDER_ADMIN&#xFF09;&#xFF1A;&#x6709;B&#x64CD;&#x4F5C;&#x6743;&#x9650;</li>
<li>&#x666E;&#x901A;&#x7528;&#x6237;&#xFF08;ROLE_NORMAL&#xFF09;&#xFF1A;&#x6709;C&#x64CD;&#x4F5C;&#x6743;&#x9650;</li>
</ul>
<p>&#x6BD4;&#x5982;&#x4E00;&#x4E2A;&#x7528;&#x6237;&#x8FDB;&#x6765;&#xFF0C;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x6839;&#x636E;&#x4E0D;&#x540C;&#x7528;&#x6237;&#x7684;&#x89D2;&#x8272;&#x6765;&#x5224;&#x65AD;&#x5176;&#x6709;&#x54EA;&#x4E9B;&#x884C;&#x4E3A;&#xFF0C;&#x8FD9;&#x65F6;&#x5019;<strong>SAO&#x4EE3;&#x7801;</strong>&#x51FA;&#x73B0;&#x4E86;&#xFF1A;</p>
<h3 id="ifelse&#x5199;&#x6CD5;">if/else&#x5199;&#x6CD5;</h3>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">JudgeRole</span> </span>{
    <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">judge</span><span class="hljs-params">(String roleName)</span> </span>{
        String result = <span class="hljs-string">&quot;&quot;</span>;
        <span class="hljs-keyword">if</span> (roleName.equals(<span class="hljs-string">&quot;ROLE_ROOT_ADMIN&quot;</span>)) {
        <span class="hljs-comment">// &#x7CFB;&#x7EDF;&#x7BA1;&#x7406;&#x5458;&#x6709;A&#x6743;&#x9650;</span>
            result = <span class="hljs-string">&quot;ROLE_ROOT_ADMIN: &quot;</span> + <span class="hljs-string">&quot;has AAA permission&quot;</span>;
        } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (roleName.equals(<span class="hljs-string">&quot;ROLE_ORDER_ADMIN&quot;</span>)) {
        <span class="hljs-comment">// &#x8BA2;&#x5355;&#x7BA1;&#x7406;&#x5458;&#x6709;B&#x6743;&#x9650;</span>
            result = <span class="hljs-string">&quot;ROLE_ORDER_ADMIN: &quot;</span> + <span class="hljs-string">&quot;has BBB permission&quot;</span>;
        } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (roleName.equals(<span class="hljs-string">&quot;ROLE_NORMAL&quot;</span>)) {
        <span class="hljs-comment">// &#x666E;&#x901A;&#x7528;&#x6237;&#x6709;C&#x6743;&#x9650;</span>
            result = <span class="hljs-string">&quot;ROLE_NORMAL: &quot;</span> + <span class="hljs-string">&quot;has CCC permission&quot;</span>;
        } <span class="hljs-keyword">else</span> {
            result = <span class="hljs-string">&quot;XXX&quot;</span>;
        }
        <span class="hljs-keyword">return</span> result;
    }
}
</code></pre>
<p>&#x200B;        &#x8FD9;&#x6837;&#x5F53;&#x7CFB;&#x7EDF;&#x91CC;&#x6709;<strong>&#x51E0;&#x5341;&#x4E2A;&#x89D2;&#x8272;</strong>&#x65F6;&#xFF0C;&#x90A3;&#x51E0;&#x5341;&#x4E2A; if/else&#x5D4C;&#x5957;&#x53EF;&#x4EE5;&#x8BF4;&#x662F;&#x975E;&#x5E38;&#x9178;&#x723D;&#x4E86;&#x2026;&#x2026; &#x8FD9;&#x6837;<strong>&#x4E00;&#x6765;</strong>&#x975E;&#x5E38;&#x4E0D;&#x4F18;&#x96C5;&#xFF0C;&#x522B;&#x4EBA;&#x9605;&#x8BFB;&#x8D77;&#x6765;&#x5F88;&#x8D39;&#x52B2;&#xFF1B;<strong>&#x4E8C;&#x6765;</strong>&#x5219;&#x662F;&#x4EE5;&#x540E;&#x5982;&#x679C;&#x518D;&#x590D;&#x6742;&#x4E00;&#x70B9;&#xFF0C;&#x6216;&#x8005;&#x60F3;&#x8981;&#x518D;&#x52A0;&#x6761;&#x4EF6;&#x7684;&#x8BDD;<strong>&#x4E0D;&#x597D;&#x6269;&#x5C55;</strong>&#xFF1B;&#x800C;&#x4E14;&#x4EE3;&#x7801;&#x4E00;&#x6539;&#xFF0C;&#x4EE5;&#x524D;&#x7684;&#x8001;&#x529F;&#x80FD;&#x80AF;&#x5B9A;&#x8FD8;&#x5F97;&#x91CD;&#x6D4B;&#xFF0C;&#x5C82;&#x4E0D;&#x75AF;&#x4E86;&#x2026;&#x2026;</p>
<h3 id="&#x4F7F;&#x7528;&#x679A;&#x4E3E;&#x7C7B;">&#x4F7F;&#x7528;&#x679A;&#x4E3E;&#x7C7B;</h3>
<p>&#x9996;&#x5148;&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x516C;&#x7528;&#x63A5;&#x53E3; RoleOperation&#xFF0C;&#x8868;&#x793A;&#x4E0D;&#x540C;&#x89D2;&#x8272;&#x6240;&#x80FD;&#x505A;&#x7684;&#x64CD;&#x4F5C;&#xFF1A;</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">interface</span> <span class="hljs-title">RoleOperation</span> </span>{
    <span class="hljs-function">String <span class="hljs-title">op</span><span class="hljs-params">()</span></span>;<span class="hljs-comment">//&#x8868;&#x793A;&#x67D0;&#x4E2A;&#x89D2;&#x8272;&#x53EF;&#x4EE5;&#x505A;&#x54EA;&#x4E9B;&#x64CD;&#x4F5C;</span>
}
</code></pre>
<p>&#x63A5;&#x4E0B;&#x6765;&#x6211;&#x4EEC;&#x5C06;&#x4E0D;&#x540C;&#x89D2;&#x8272;&#x7684;&#x60C5;&#x51B5;&#x5168;&#x90E8;&#x4EA4;&#x7531;&#x679A;&#x4E3E;&#x7C7B;&#x6765;&#x505A;&#xFF0C;&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x4E0D;&#x540C;&#x89D2;&#x8272;&#x6709;&#x4E0D;&#x540C;&#x6743;&#x9650;&#x7684;&#x679A;&#x4E3E;&#x7C7B; RoleEnum&#xFF1A;</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-keyword">enum</span> RoleEnum implements RoleOperation {
    <span class="hljs-comment">// &#x7CFB;&#x7EDF;&#x7BA1;&#x7406;&#x5458;(&#x6709;A&#x64CD;&#x4F5C;&#x6743;&#x9650;)</span>
    ROLE_ROOT_ADMIN {
        <span class="hljs-meta">@Override</span>
        <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">op</span><span class="hljs-params">()</span> </span>{
            <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;ROLE_ROOT_ADMIN:&quot;</span> + <span class="hljs-string">&quot; has AAA permission&quot;</span>;
        }
    },

    <span class="hljs-comment">// &#x8BA2;&#x5355;&#x7BA1;&#x7406;&#x5458;(&#x6709;B&#x64CD;&#x4F5C;&#x6743;&#x9650;)</span>
    ROLE_ORDER_ADMIN {
        <span class="hljs-meta">@Override</span>
        <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">op</span><span class="hljs-params">()</span> </span>{
            <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;ROLE_ORDER_ADMIN:&quot;</span> + <span class="hljs-string">&quot; has BBB permission&quot;</span>;
        }
    },

    <span class="hljs-comment">// &#x666E;&#x901A;&#x7528;&#x6237;(&#x6709;C&#x64CD;&#x4F5C;&#x6743;&#x9650;)</span>
    ROLE_NORMAL {
        <span class="hljs-meta">@Override</span>
        <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">op</span><span class="hljs-params">()</span> </span>{
            <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;ROLE_NORMAL:&quot;</span> + <span class="hljs-string">&quot; has CCC permission&quot;</span>;
        }
    };

}
</code></pre>
<p>&#x63A5;&#x4E0B;&#x6765;&#x8C03;&#x7528;&#x5C31;&#x53D8;&#x5F97;&#x5F02;&#x5E38;&#x7B80;&#x5355;&#x4E86;&#xFF0C;&#x4E00;&#x884C;&#x4EE3;&#x7801;&#x5C31;&#x884C;&#x4E86;&#xFF0C; if/else&#x4E5F;&#x7070;&#x98DE;&#x70DF;&#x706D;&#x4E86;&#xFF1A;</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">JudgeRoleByEnum</span> </span>{
    <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">judge</span><span class="hljs-params">(String roleName)</span> </span>{
    <span class="hljs-comment">// &#x4E00;&#x884C;&#x4EE3;&#x7801;&#x641E;&#x5B9A;&#xFF01;&#x4E4B;&#x524D;&#x7684;if/else&#x6CA1;&#x4E86;&#xFF01;</span>
        <span class="hljs-keyword">return</span> RoleEnum.valueOf(roleName).op();
    }
}
</code></pre>
<p>&#x800C;&#x4E14;&#x8FD9;&#x6837;&#x4E00;&#x6765;&#xFF0C;&#x4EE5;&#x540E;&#x5047;&#x5982;&#x6211;&#x60F3;&#x6269;&#x5145;&#x6761;&#x4EF6;&#xFF0C;&#x53EA;&#x9700;&#x8981;&#x53BB;&#x679A;&#x4E3E;&#x7C7B;&#x4E2D;&#x52A0;&#x4EE3;&#x7801;&#x5373;&#x53EF;&#xFF0C;&#x800C;&#x4E0D;&#x662F;&#x53BB;&#x6539;&#x4EE5;&#x524D;&#x7684;&#x4EE3;&#x7801;&#xFF0C;&#x8FD9;&#x5C82;&#x4E0D;&#x5F88;&#x7A33;&#xFF01;</p>
<h3 id="&#x5DE5;&#x5382;&#x6A21;&#x5F0F;">&#x5DE5;&#x5382;&#x6A21;&#x5F0F;</h3>
<blockquote>
<p>&#x9700;&#x8981;&#x4E0A;&#x9762;&#x5B9A;&#x4E49;&#x7684;&#x63A5;&#x53E3;</p>
</blockquote>
<p>&#x9996;&#x5148;&#xFF0C;&#x9488;&#x5BF9;&#x4E0D;&#x540C;&#x7684;&#x89D2;&#x8272;&#xFF0C;&#x5355;&#x72EC;&#x5B9A;&#x4E49;&#x5176;&#x4E1A;&#x52A1;&#x7C7B;&#xFF1A;</p>
<pre><code class="lang-java"><span class="hljs-comment">// &#x7CFB;&#x7EDF;&#x7BA1;&#x7406;&#x5458;(&#x6709;A&#x64CD;&#x4F5C;&#x6743;&#x9650;)</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">RootAdminRole</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">RoleOperation</span> </span>{
    <span class="hljs-keyword">private</span> String roleName;
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">RootAdminRole</span><span class="hljs-params">(String roleName )</span></span>{
        <span class="hljs-keyword">this</span>.roleName = roleName;
    }
    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">op</span><span class="hljs-params">()</span> </span>{
        <span class="hljs-keyword">return</span> roleName +<span class="hljs-string">&quot; has AAA permission&quot;</span>;
    }
}
</code></pre>
<pre><code class="lang-java"><span class="hljs-comment">// &#x8BA2;&#x5355;&#x7BA1;&#x7406;&#x5458;(&#x6709;B&#x64CD;&#x4F5C;&#x6743;&#x9650;)</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">OrderAdminRole</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">RoleOperation</span> </span>{
    <span class="hljs-keyword">private</span> String roleName;
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">OrderAdminRole</span><span class="hljs-params">(String roleName )</span></span>{
        <span class="hljs-keyword">this</span>.roleName = roleName;
    }
    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">op</span><span class="hljs-params">()</span> </span>{
        <span class="hljs-keyword">return</span> roleName +<span class="hljs-string">&quot; has BBB permission&quot;</span>;
    }
}
</code></pre>
<pre><code class="lang-java"><span class="hljs-comment">// &#x666E;&#x901A;&#x7528;&#x6237;(&#x6709;C&#x64CD;&#x4F5C;&#x6743;&#x9650;)</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">NormalRole</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">RoleOperation</span> </span>{
    <span class="hljs-keyword">private</span> String roleName;
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">NormalRole</span><span class="hljs-params">(String roleName )</span></span>{
        <span class="hljs-keyword">this</span>.roleName = roleName;
    }
    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">op</span><span class="hljs-params">()</span> </span>{
        <span class="hljs-keyword">return</span> roleName +<span class="hljs-string">&quot; has CCC permission&quot;</span>;
    }
}
</code></pre>
<p>&#x63A5;&#x4E0B;&#x6765;&#x518D;&#x5199;&#x4E00;&#x4E2A;<strong>&#x5DE5;&#x5382;&#x7C7B;</strong> <strong>RoleFactory</strong>&#x5BF9;&#x4E0A;&#x9762;&#x4E0D;&#x540C;&#x89D2;&#x8272;&#x8FDB;&#x884C;&#x805A;&#x5408;&#xFF1A;</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">RoleFactory</span> </span>{
    <span class="hljs-keyword">static</span> Map&lt;String, RoleOperation&gt; roleOperationMap = <span class="hljs-keyword">new</span> HashMap&lt;&gt;();


    <span class="hljs-comment">//&#x5728;&#x9759;&#x6001;&#x5757;&#x4E2D;&#x5148;&#x628A;&#x521D;&#x59CB;&#x5316;&#x5DE5;&#x4F5C;&#x5168;&#x90E8;&#x505A;&#x5B8C;</span>
    <span class="hljs-keyword">static</span> {
        roleOperationMap.put(<span class="hljs-string">&quot;ROLE_ROOT_ADMIN&quot;</span>,<span class="hljs-keyword">new</span> RootAdminRole(<span class="hljs-string">&quot;ROLE_ROOT_ADMIN&quot;</span>));
        roleOperationMap.put(<span class="hljs-string">&quot;ROLE_ORDER_ADMIN&quot;</span>,<span class="hljs-keyword">new</span> RootAdminRole(<span class="hljs-string">&quot;ROLE_ORDER_ADMIN&quot;</span>));
        roleOperationMap.put(<span class="hljs-string">&quot;ROLE_NORMAL&quot;</span>,<span class="hljs-keyword">new</span> RootAdminRole(<span class="hljs-string">&quot;ROLE_NORMAL&quot;</span>));
    }
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> RoleOperation <span class="hljs-title">getOp</span><span class="hljs-params">(String roleName)</span></span>{
        <span class="hljs-keyword">return</span> roleOperationMap.get(roleName);
    }
}
</code></pre>
<p>&#x63A5;&#x4E0B;&#x6765;&#x501F;&#x52A9;&#x4E0A;&#x9762;&#x8FD9;&#x4E2A;&#x5DE5;&#x5382;&#xFF0C;&#x4E1A;&#x52A1;&#x4EE3;&#x7801;&#x8C03;&#x7528;&#x4E5F;&#x53EA;&#x9700;&#x4E00;&#x884C;&#x4EE3;&#x7801;&#xFF0C; if/else&#x540C;&#x6837;&#x88AB;&#x6D88;&#x9664;&#x4E86;</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">JudgeRoleByFactory</span> </span>{
    <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">judge</span><span class="hljs-params">(String roleName)</span></span>{
        <span class="hljs-comment">//1&#x884C;&#x4EE3;&#x7801;&#x641E;&#x5B9A;&#xFF01;&#x4E4B;&#x524D;&#x7684;if/else&#x4E5F;&#x6CA1;&#x4E86;!</span>
        <span class="hljs-keyword">return</span> RoleFactory.getOp(roleName).op();
    }
}
</code></pre>
<p>&#x8FD9;&#x6837;&#x7684;&#x8BDD;&#x4EE5;&#x540E;&#x60F3;&#x6269;&#x5C55;&#x6761;&#x4EF6;&#x4E5F;&#x5F88;&#x5BB9;&#x6613;&#xFF0C;&#x53EA;&#x9700;&#x8981;&#x589E;&#x52A0;&#x65B0;&#x4EE3;&#x7801;&#xFF0C;&#x800C;&#x4E0D;&#x9700;&#x8981;&#x52A8;&#x4EE5;&#x524D;&#x7684;&#x4E1A;&#x52A1;&#x4EE3;&#x7801;&#xFF0C;&#x975E;&#x5E38;&#x7B26;&#x5408;<strong>&#x201C;&#x5F00;&#x95ED;&#x539F;&#x5219;&#x201D;</strong>&#x3002;</p>
<h3 id="&#x7B56;&#x7565;&#x6A21;&#x5F0F;">&#x7B56;&#x7565;&#x6A21;&#x5F0F;</h3>
<p>&#x5728;&#x4E0A;&#x9762;&#x5DE5;&#x5382;&#x6A21;&#x5F0F;&#x4EE3;&#x7801;&#x7684;&#x57FA;&#x7840;&#x4E0A;(&#x9700;&#x8981;&#x63A5;&#x53E3;)</p>
<p>&#x6309;&#x7167;&#x7B56;&#x7565;&#x6A21;&#x5F0F;&#x7684;&#x6307;&#x5BFC;&#x601D;&#x60F3;&#xFF0C;&#x6211;&#x4EEC;&#x4E5F;&#x6765;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x6240;&#x8C13;&#x7684;<strong>&#x7B56;&#x7565;&#x4E0A;&#x4E0B;&#x6587;&#x7C7B;</strong>&#xFF0C;&#x8FD9;&#x91CC;&#x547D;&#x540D;&#x4E3A; RoleContext&#xFF1A;</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">RoleContext</span> </span>{
    <span class="hljs-comment">//&#x53EF;&#x66F4;&#x6362;&#x7684;&#x7B56;&#x7565;&#xFF0C;&#x4F20;&#x5165;&#x4E0D;&#x540C;&#x7684;&#x7B56;&#x7565;&#x5BF9;&#x8C61;&#xFF0C;&#x4E1A;&#x52A1;&#x5373;&#x76F8;&#x5E94;&#x53D8;&#x5316;</span>
    <span class="hljs-keyword">private</span> RoleOperation operation;


    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">RoleContext</span><span class="hljs-params">(RoleOperation operation)</span></span>{
        <span class="hljs-keyword">this</span>.operation=operation;
    }


    <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">execute</span><span class="hljs-params">()</span></span>{
        <span class="hljs-keyword">return</span> operation.op();
    }
}
</code></pre>
<p>&#x5F88;&#x660E;&#x663E;&#x4E0A;&#x9762;&#x4F20;&#x5165;&#x7684;&#x53C2;&#x6570; operation&#x5C31;&#x662F;&#x8868;&#x793A;&#x4E0D;&#x540C;&#x7684;<strong>&#x201C;&#x7B56;&#x7565;&#x201D;</strong>&#x3002;&#x6211;&#x4EEC;&#x5728;&#x4E1A;&#x52A1;&#x4EE3;&#x7801;&#x91CC;&#x4F20;&#x5165;&#x4E0D;&#x540C;&#x7684;&#x89D2;&#x8272;&#xFF0C;&#x5373;&#x53EF;&#x5F97;&#x5230;&#x4E0D;&#x540C;&#x7684;&#x64CD;&#x4F5C;&#x7ED3;&#x679C;&#xFF1A;</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">JudgeRoleByContext</span> </span>{
    <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">judge</span><span class="hljs-params">(RoleOperation roleOperation)</span></span>{
        RoleContext roleContext = <span class="hljs-keyword">new</span> RoleContext(roleOperation);
        <span class="hljs-keyword">return</span> roleContext.execute();
    }
}
</code></pre>
<pre><code class="lang-java"><span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>{
    JudgeRoleByContext judgeRoleByContext = <span class="hljs-keyword">new</span> JudgeRoleByContext();
    String result1 = judgeRoleByContext.judge(<span class="hljs-keyword">new</span> RootAdminRole(<span class="hljs-string">&quot;ROLE_ROOT_ADMIN&quot;</span>));
    System.out.println(result1);
    String result2 = judgeRoleByContext.judge(<span class="hljs-keyword">new</span> OrderAdminRole(<span class="hljs-string">&quot;ROLE_ORDER_ADMIN&quot;</span>));
    System.out.println(result2);
    String result3 = judgeRoleByContext.judge(<span class="hljs-keyword">new</span> NormalRole(<span class="hljs-string">&quot;ROLE_NORMAL&quot;</span>));
    System.out.println(result3);
}
</code></pre>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="jvm.html" class="navigation navigation-prev " aria-label="Previous page: Jvm">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="socket.html" class="navigation navigation-next " aria-label="Next page: Socket">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"Noifelse","level":"1.8.11","depth":2,"next":{"title":"Socket","level":"1.8.12","depth":2,"path":"学习java/socket.md","ref":"学习java/socket.md","articles":[]},"previous":{"title":"Jvm","level":"1.8.10","depth":2,"path":"学习java/jvm.md","ref":"学习java/jvm.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-search","-lunr","-sharing","-anchor-navigation-ex","todo","code","-katex","github","-summary","search-pro","chapter-fold","theme-comscore","toggle-chapters","flexible-alerts"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"chapter-fold":{},"github":{"url":"https://github.com/BluePrintYang"},"todo":{},"search-pro":{},"code":{"copyButtons":true},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"anchor-navigation-ex":{"showLevel":false,"showGoTop":true,"isRewritePageTitle":true,"isShowTocTitleIcon":true,"tocLevel1Icon":"fa fa-hand-o-right","tocLevel2Icon":"fa fa-hand-o-right","tocLevel3Icon":"fa fa-hand-o-right"},"theme-comscore":{},"flexible-alerts":{"danger":{"className":"danger","icon":"fa fa-ban","label":"Attention"},"note":{"className":"info","icon":"fa fa-info-circle","label":"Note"},"style":"callout","tip":{"className":"tip","icon":"fa fa-lightbulb-o","label":"Tip"},"warning":{"className":"warning","icon":"fa fa-exclamation-triangle","label":"Warning"}},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"toggle-chapters":{}},"theme":"default","author":"yanglonglong","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"My Study Note","language":"zh-hans","links":{"sidebar":{"My Blog":"https://www.yangllong.top/"}},"gitbook":"*"},"file":{"path":"学习java/noifelse.md","mtime":"2020-06-29T16:04:36.000Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-01-14T07:15:50.272Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-github/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-toggle-chapters/toggle.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-flexible-alerts/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-theme-comscore/test.js"></script>
        
    

    </body>
</html>

